package com.hy.mydesktop.client.component.factory;

import com.extjs.gxt.charts.client.Chart;
import com.extjs.gxt.charts.client.model.ChartModel;
import com.hy.mydesktop.client.component.meta.ChartModelEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;

/**
 * 
 * <ul>
 * <li>开发作者：汤莉</li>
 * <li>设计日期：2010-9-7；时间：下午01:04:51</li>
 * <li>类型名称：ChartFactory</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
public class ChartFactory {
	
	/**
	 * 
	 * <ul>
	 * <li>方法含义：创建chart</li>
	 * <li>方法作者：汤莉</li>
	 * <li>编写日期：2010-9-7；时间：下午下午01:07:46</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param gxtComponentMetaNodeModel
	 * @return
	 */
	public static Chart createChart(GxtComponentMetaNodeModel gxtComponentMetaNodeModel)
	{
		return configureChart(gxtComponentMetaNodeModel);
	}

	/**
	 * 
	 * <ul>
	 * <li>方法含义：配置chart属性</li>
	 * <li>方法作者：汤莉</li>
	 * <li>编写日期：2010-9-7；时间：下午下午01:08:05</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param gxtComponentMetaNodeModel
	 * @return
	 */
	private static Chart configureChart(GxtComponentMetaNodeModel gxtComponentMetaNodeModel)
	{
		Chart chart=defaultCreateChart((String)gxtComponentMetaNodeModel.get(ChartModelEnum.URL.name().toLowerCase()));
		if(gxtComponentMetaNodeModel.get(ChartModelEnum.BORDERS.name().toLowerCase())!=null)
		{
			boolean border=(Boolean)gxtComponentMetaNodeModel.get(ChartModelEnum.BORDERS.name().toLowerCase());
			chart.setBorders(border);
		}
		if(gxtComponentMetaNodeModel.get(ChartModelEnum.CHARTMODEL.name().toLowerCase())!=null)
		{
//			gxtComponentMetaNodeModel.set("backgroundcolour", "#fffff5");
//			gxtComponentMetaNodeModel.set("legend", "aa");
//			gxtComponentMetaNodeModel.set("addchartconfig", "aa");
			ChartModel chartModel=ChartModelFactory.createChartModel(gxtComponentMetaNodeModel);
			chart.setChartModel(chartModel);
		}
		return chart;
	}
	
	private static Chart defaultCreateChart(String url)
	{
		 url="resources/chart/open-flash-chart.swf";
		Chart chart=new Chart(url);//传一个参数进来
		return chart;
	}
}
